package io.choerodon.iam.api.validator;

import io.choerodon.core.exception.CommonException;
import io.choerodon.iam.infra.constant.ExceptionConstants;

import org.apache.commons.lang3.ObjectUtils;
import org.hzero.iam.domain.entity.Ldap;
import org.springframework.util.StringUtils;

/**
 * @author superlee
 */
public class LdapValidator {

    private LdapValidator() {
    }

    public static void validate(Ldap ldap) {
        if (ObjectUtils.isEmpty(ldap.getServerAddress())) {
            throw new CommonException(ExceptionConstants.LdapErrorCode.IAM_LDAP_SERVERADDRESS_EMPTY);
        }
        if (ObjectUtils.isEmpty(ldap.getLoginNameField())) {
            throw new CommonException(ExceptionConstants.LdapErrorCode.IAM_LDAP_LOGINNAMEFIELD_EMPTY);
        }
        if (ObjectUtils.isEmpty(ldap.getEmailField())) {
            throw new CommonException(ExceptionConstants.LdapErrorCode.IAM_LDAP_EMAILFIELD_EMPTY);
        }
        if (ObjectUtils.isEmpty(ldap.getObjectClass())) {
            throw new CommonException(ExceptionConstants.LdapErrorCode.IAM_LDAP_OBJECTCLASS_EMPTY);
        }
    }
}
